import  get_hwnd
import cv2
from  PIL import ImageGrab
import find_image
import local_const
import pyautogui
import time

class GoModule:
    left = 0
    top = 0
    right = 0
    bottom = 0
    def openSmallMap(self):
        pyautogui.rightClick(self.left + local_const.map['x'], self.top + local_const.map['y'])
        time.sleep(2 * local_const.timeUnit)
        ImageGrab.grab((self.left, self.top, self.right, self.bottom)).save("image/tempImg.png")
        winImg = cv2.imread("image/tempImg.png")
        toFind = cv2.imread("image/map_pos_site.bmp")
        minLoc = find_image.fastFind(winImg, toFind)
        if minLoc == -1:
            time.sleep(3 * local_const.timeUnit)
            pyautogui.hotkey('tab')
            time.sleep(4 * local_const.timeUnit)
            ImageGrab.grab((self.left, self.top, self.right, self.bottom)).save("image/tempImg.png")
            winImg = cv2.imread("image/tempImg.png")
            toFind = cv2.imread("image/map_pos_site.bmp")
            minLoc = find_image.fastFind(winImg, toFind)
        return minLoc
    # 去江南野外
    def toJNYW(self):
        minLoc = self.openSmallMap()
        pyautogui.move(minLoc[0] + self.left + local_const.toJNYW['x'],
                       minLoc[1] + self.top + local_const.toJNYW['y'], duration=2.5 * local_const.timeUnit)
        time.sleep(local_const.timeUnit)
        pyautogui.mouseDown(minLoc[0] + self.left + local_const.toJNYW['x'], minLoc[1] + self.top + local_const.toJNYW['y'])
        time.sleep(local_const.timeUnit)
        pyautogui.mouseUp(minLoc[0] + self.left + local_const.toJNYW['x'], minLoc[1] + self.top + local_const.toJNYW['y'])
        time.sleep(6)
        pyautogui.move(self.left + local_const.toJNYWTrans['x'],
                       self.top + local_const.toJNYWTrans['y'], duration=2.5 * local_const.timeUnit)
        time.sleep(2.5 * local_const.timeUnit)
        pyautogui.mouseDown(self.left + local_const.toJNYWTrans['x'], self.top + local_const.toJNYWTrans['y'])
        time.sleep(3)
        pyautogui.mouseUp(self.left + local_const.toJNYWTrans['x'], self.top + local_const.toJNYWTrans['y'])
    def toJYC(self):
        minLoc = self.openSmallMap()
        pyautogui.move(minLoc[0] + self.left + local_const.toJYC['x'],
                       minLoc[1] + self.top + local_const.toJYC['y'], duration=2.5 * local_const.timeUnit)
        time.sleep(local_const.timeUnit)
        pyautogui.mouseDown(minLoc[0] + self.left + local_const.toJYC['x'], minLoc[1] + self.top + local_const.toJYC['y'])
        time.sleep(local_const.timeUnit)
        pyautogui.mouseUp(minLoc[0] + self.left + local_const.toJYC['x'], minLoc[1] + self.top + local_const.toJYC['y'])
        time.sleep(6)
        # pyautogui.move(self.left + local_const.toJNYWTrans['x'],
        #                self.top + local_const.toJNYWTrans['y'], duration=2.5 * local_const.timeUnit)
        # time.sleep(2.5 * local_const.timeUnit)
        # pyautogui.mouseDown(self.left + local_const.toJNYWTrans['x'], self.top + local_const.toJNYWTrans['y'])
        # time.sleep(3)
        # pyautogui.mouseUp(self.left + local_const.toJNYWTrans['x'], self.top + local_const.toJNYWTrans['y'])